package com.hankol.newretail.adapter.details

import android.text.TextUtils
import android.view.View
import com.baselibrary.bean.StreamData
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.*
import com.baselibrary.view.SmallVipHeardImgView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.newretail.R
import com.hankol.newretail.bean.goods_details.GrassShowBean
import com.like.LikeButton
import com.like.OnLikeListener

/**
 * @author: 关忆北、
 * @date: 2022/7/29
 * @Des：种草秀详情
 */
class GoodsPlantInfoAdapter : BaseQuickAdapter<GrassShowBean, BaseViewHolder>(R.layout.item_common_dynamic) {
    private var mCallback: Callback? = null

    interface Callback {
        fun onClickLike(position: Int, item: StreamData.DataDTO.Data)
    }

    override fun convert(helper: BaseViewHolder, timeline: GrassShowBean) {

        ImageUtils.setImageViewSize(helper.getView(R.id.iv_dynamic_cover), false)
        GlideUtils.loadImg_228(mContext, timeline.cover, helper.getView(R.id.iv_dynamic_cover))
        helper.setText(R.id.tv_dynamic_title, timeline.desc)
        val vipHeardImgView = helper.getView<SmallVipHeardImgView>(R.id.iv_dynamic_head)
        vipHeardImgView.setData(timeline.authorIcon, timeline.isFans == 1, View.INVISIBLE)
        helper.setText(R.id.tv_dynamic_username, timeline.author)
        helper.setText(R.id.tv_dynamic_like_number, NumberUtils.formatBigNum(timeline.supportNum.toString()))
        val likeStatus: LikeButton = helper.getView(R.id.iv_dynamic_like)
        likeStatus.isLiked = timeline.supported
        likeStatus.setOnLikeListener(object : OnLikeListener {
            override fun liked(likeButton: LikeButton?) {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    timeline.supportNum += 1
                    helper.setText(R.id.tv_dynamic_like_number, NumberUtils.formatBigNum(timeline.supportNum.toString()))

                }
            }

            override fun unLiked(likeButton: LikeButton?) {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    timeline.supportNum -= 1
                    if (timeline.supportNum <= 0) {
                        timeline.supportNum = 0
                    }
                    helper.setText(R.id.tv_dynamic_like_number, NumberUtils.formatBigNum(timeline.supportNum.toString()))
                }
            }
        })
        helper.setVisible(R.id.iv_play, timeline.showType == 2)
        helper.setGone(R.id.tv_dynamic_title, !TextUtils.isEmpty(timeline.desc))
        helper.itemView.setOnClickListener {
            if (!DoubleClickHelper.isOnDoubleClick()) {
                if (timeline.showType == 2) {
                    val hashMap = HashMap<String, Any>()
                    hashMap["id"] = timeline.id
                    hashMap["isOpenComment"] = false
                    hashMap["JumpType"] = 0
                    hashMap["source"] = timeline.tagCategoryName
                    hashMap["bid"] = timeline.id.toString()
                    ARouterUtils.jump(ActivityRouter.ACTIVITY.READ_VIDEO_DETAIL, hashMap, helper.getView(R.id.iv_dynamic_cover))
                } else {
                    val hashMap = HashMap<String, Any>()
                    hashMap["id"] = timeline.id.toString()
                    hashMap["source"] = timeline.tagCategoryName
                    ARouterUtils.jump(ActivityRouter.ACTIVITY.IMAGE_DETAIL, hashMap, helper.getView(R.id.iv_dynamic_cover))
                }
            }
        }

    }

}